#include "ProcessFunctions.h"

// Compile: g++ -o3 main.cpp ProcessFunctions.cpp -o main.exe

int main(int argc, char *argv[])
{
	// 准备工作：读入图像，建立输出图像
	HXLBMPFILE bmpfile;
	int i, j;
	if (!bmpfile.LoadBMPFILE("./image/1.bmp")) // 载入bmp图像
		exit(1);							   // 不成功则退出

	HXLBMPFILE bf; // 建立输出bmp对象
	bf.imagew = bmpfile.imagew;
	bf.imageh = bmpfile.imageh;
	bf.iYRGBnum = bmpfile.iYRGBnum;
	if (bf.iYRGBnum == 1)
	{
		*bf.palette = *bmpfile.palette; // 对灰度图需复制调色板
	}
	if (!bf.AllocateMem())
		return 1;

	// 实验2
	// 1、绘出原图像直方图SH
	float *SH = outHistogramData(bmpfile, "./output/SH.txt");

	// 2、绘出直方图SH的均衡直方图SQH，均衡图像QI。下面二选一均可
	HistEqualize(bmpfile, bf, "./output/SQH.txt");
	// HistEqualize(bmpfile, bf, SH, "SQH.txt");

	// 3、绘出目标直方图EH的均衡直方图EQH
	float *target_hist = getTargetHist("./output/target_hist.txt"); // target_hist指向目标直方图得到的灰阶-概率数组
	HistEqualize(bmpfile, bf, target_hist, "./output/EQH.txt");

	// 4、绘出规定化变换函数T，给出最终增强图像DI和直方图DH
	HistSpecificate(bmpfile, bf, target_hist, "./output/DH.txt");

	return 0;
}